package distribution;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import dto.Sample;

public class GaussianDistribution implements Distribution {
	List<UniGaussian> model;
	
	@Override
	public double getLogProb(Sample sample) {
		int dim = model.size();
		double log = 0;
		for(int i = 0; i < dim; i++) {
			log += model.get(i).predict(sample.getPoint().getValue(i + 1));
		}
		return log;
	}

	@Override
	public void train(List<List<Sample>> samples, int dim) {
		
		List<Sample> allSamples = new LinkedList<Sample>();
		for(List<Sample> list : samples) {
			allSamples.addAll(list);
		}

		model = new ArrayList<UniGaussian>(dim);
		for(int i = 1; i <= dim; i++) {
			List<Double> values = new LinkedList<Double>();
			for(Sample sample : allSamples) {
				values.add(sample.getPoint().getValue(i));
			}
			UniGaussian ug = new UniGaussian();
			ug.train(values);
			model.add(ug);
		}
	}
}
